package com.example.mapper;

import com.example.entity.SecKillSku;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import tk.mybatis.mapper.common.Mapper;

/**
 * (SecKillSku)表数据库访问层
 *
 * @author 游家纨绔
 * @since 2023-08-30 12:30:00
 */
public interface SkuMapper extends Mapper<SecKillSku> {

	@Select("""
            select k.*
			from (SELECT min(price) as pr FROM second_kill_sku) p 
			    INNER JOIN second_kill_sku k 
			WHERE p.pr = k.price and k.spu_id=#{id}
			""")
	SecKillSku queryMinPriceSku(Integer id);

	@Update("""
			UPDATE second_kill_sku 
			SET stock = stock-1 
			WHERE id = #{id} and stock>0
			""")
	int updateStockById(Integer id);

}
